package cn.dlc.com.demo.controller;

import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @Author dlc
 * @Date 2023/12/16
 * @Description TODO
 * @Version 0.0.1
 */
public class DemoController {

    @Resource(name = "redissonClient1")
    private RedissonClient redissonClient;
    @Resource(name = "redissonClient2")
    private RedissonClient redissonClient2;

    public void testRedissonLock() throws Exception{
        // 获取两个独立的锁
        RLock lock = redissonClient.getLock("lock");
        RLock lock2 = redissonClient2.getLock("lock");
        // 获取连锁
        RLock multiLock = redissonClient.getMultiLock(lock, lock2);
        // 加锁
        boolean lock1 = multiLock.tryLock(1L, TimeUnit.MINUTES);
    }
}
